﻿using System;
using BEGDC.CC.Entity;
using BEGDC.CC.BL.Common;
using BEGDC.CC.BL.Common.Query;
using BEGDC.Utility.Castle;

namespace BEGDC.CC.Web.UserControls.EBDCV
{
	/// <summary>
	/// Summary description for BaseCR.
	/// </summary>
	public class BaseEBDCV : BaseCtrl
	{
		public BaseEBDCV()
		{
		}

		protected void PreInitForm()
		{
			string RequestApp = Request.QueryString["AppID"];
			if( RequestApp == null || RequestApp == String.Empty ) RequestApp = "0";
			this.AppID = Convert.ToInt32( RequestApp );
			this.Application = null;

			//base.InitFlowInfo( this.ProjectId,myStep );

			if( this.AppID <0)
			{
				WebUtility.Go2ErrorPage( this.Page, "wrong Application ID" );
			}

			if(!Page.IsPostBack)
			{
				Session[SessionFlag.AccompanySessionEZ] = null;
				Session[SessionFlag.CustomerSessionEZ] = null;
				Session[SessionFlag.ContractInfo] = null;
				Session[SessionFlag.CostCenter] = null;
			}
		}

		protected long LoadApplication()
		{
			int appid = this.AppID;
			long flowId = 0;

			BEGDC.CC.Entity.Application app = null;

			if( appid > 0 )
			{
				IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
				app = queryService.GetAppById(appid);

				FlowInstance flowInstance = queryService.QueryFlowInstance(appid);
				if( flowInstance != null )
				{
					flowId = flowInstance.Id;
				}
				else
				{
					flowId = 0;
				}
			}

			this.Application = app;	

			return flowId;
		}
	}
}